const express = require("express");
const app = express();
const router = express.Router();

const { mysql,executeQuery } = require("../../mysql");

router.post("/logn",  async (req, res) => {
  



  let sql = `select * from ${req.body.col} where id ='${req.body.id}' and password='${req.body.password}';`;

  try {
    const result = await executeQuery(sql)//执行sql语句

    console.log(result);

    // if (  )
    
    res.json({
      res: result?.length == 1,
      id: req.body.id,
      user: req.body.id,
      name:result[0].name,
      subject:result[0].subject,
      is_class_teacher : result[0].is_class_teacher ?  result[0].is_class_teacher : null,
      grade : result[0].grade,
      class_name : result[0].class_name,
      major : result[0].major , 
      major_id : result[0].major_id , 
      created_at : result[0].created_at
    });

  } catch (error) {

    console.error('Error executing query:', error);
    res.status(500).send('Internal Server Error');

  }
});

module.exports = router;
